<?php
session_start();

?>
<script>document.location.href = '#preinscription';</script>
<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Portail web dédié à la Gestion Administrative et Pédagogique du Master 2 de Recherche Système Complexe UMMISCO">
    <meta name="author" content="DIC1 Génie Info 2013-2014 / ESP Dakar">
    <meta http-equiv="Content-Language" content="fr" />
    <link rel="shortcut icon" href="../assets/ico/favicon.png">

    <title> UMMISCO - Master 2 SysCom </title>

    <!-- Bootstrap core CSS -->
    <link href="../assets/css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../assets/css/main.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/icomoon.css">
    <link href="assets/css/animate-custom.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/bootstrap.css"/>
	<link rel="stylesheet" href="../assets/css/bootstrapValidator.min.css"/>


    
    <link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Raleway:400,300,700' rel='stylesheet' type='text/css'>
    
    
    
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="assets/js/html5shiv.js"></script>
      <script src="assets/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body data-spy="scroll" data-offset="0" data-target="#navbar-main">
  
  	<div id="navbar-main">
      <!-- Fixed navbar -->
   <div class="navbar navbar-inverse navbar-fixed-top" id="header-main">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon icon-shield" style="font-size:30px; color:#3498db;"></span>
          </button>
          <a class="navbar-brand hidden-xs hidden-sm" href="#home"><span class="glyphicon glyphicon-home"></span></a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li><a href="../index.php#home" class="smoothScroll">Accueil</a></li>
			<li> <a href="../index.php#about" class="smoothScroll"> Présentation </a></li>
			<li> <a href="../index.php#direction" class="smoothScroll"> Direction</a></li>
			<li> <a href="../index.php#team" class="smoothScroll"> Recherche </a></li>
			<li> <a href="../index.php#portfolio" class="smoothScroll"> Formation </a></li>
			<li> <a href="../index.php#blog" class="smoothScroll"> Pré-inscription</a></li>
			<li> <a href="../index.php#contact" class="smoothScroll"> Contact</a></li>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    </div>

		<!-- ==== HEADERWRAP ==== -->
	    <div id="headerwrap" id="home" name="home">
			<header class="clearfix">
	  		 		<!--
	  		 		<h1><span class="icon icon-shield"></span></h1>
	  		 		<p>U M M I S C O</p>
	  		 		<p>Unité de Modélisation Mathématique et Informatique de Systèmes COmplexes</p>
	  		 		-->
	  		</header>	    
	    </div><!-- /headerwrap -->
		
		<div class="container" name="pre-inscription" id="pre-inscription">
			<a name="preinscription"></a>
			<div class="row white">
			 <h1 class="centered"> Pré-inscription </h1>
			<?php
					if (!isset($_POST['email'])){
						
                    echo "
                    <p class='centered'> Indentifiez-vous </p>
                   
                    <form class='col-lg-12' action='connexion.php' method='POST'>
	                   <div class='form-group'>
					        <input type='text' class='form-control' name='email' placeholder='Entrer votre adresse email' />
					   </div>
					     <div class='form-group'>
					        <input type='password' class='form-control' name='password' placeholder='Entrer votre adresse mot de passe' />
					   </div>
						    <span class='input-group-btn'>
				               <button class='btn btn-primary btn-lg btn-block' type='submit'>ENVOYER</button>
				            </span>
	                </form>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    "; 
                    } else {
						if (isset ($_POST['email'])) {
                            $email = $_POST['email']; //Pour ne pas surcharger la requête avec des $_POST
                            $passwd = $_POST['password'];
                            
                            include_once '../assets/config/mysql.php';
							
							// Selection dans la table CANDIDAT
		                    $requete = "SELECT * FROM Candidat WHERE email='".$_POST['email']."';";
                            $resultat = mysqli_query($db, $requete) or die("Error: ". mysqli_error($db));
                            $row = mysqli_fetch_array($resultat, MYSQLI_NUM);		
		                    $_SESSION["ID_CANDIDAT"] = $row[0];
                            $_SESSION["prenom"] = $row[1];
                            $_SESSION["nom"] = $row[2];
                            $_SESSION["password"] = $row[3];
                            $_SESSION["telephone"] = $row[4];
                            $_SESSION["adresse"] = $row[5];
                            $_SESSION["email"] = $row[6];
                            $_SESSION["dateNaiss"] = $row[7];
                            $_SESSION["lieuNaiss"] = $row[8];
                            $_SESSION["genre"] = $row[9];
                            $_SESSION["pays"] = $row[10];
							
							// Récupération du diplôme de baccalauréat
							$requete = "SELECT * FROM `diplome_candidat` WHERE `id_candidat`=".$_SESSION["ID_CANDIDAT"]." and libelle='Bac';";
							$resultat = mysqli_query($db, $requete) or die("Error1: ". mysqli_error($db));
							$row = mysqli_fetch_array($resultat, MYSQLI_NUM);
							$_SESSION['serie_bac'] = $row[3];
							$_SESSION['annee_bac'] = $row[4];
							$_SESSION['mention_bac'] = $row[5]; 
							$_SESSION['ecole_bac'] = $row[6];
							
							// Récupération d'autres diplômes
							$requete = "SELECT * FROM `diplome_candidat` WHERE `id_candidat`=".$_SESSION["ID_CANDIDAT"]." and libelle <> 'Bac';";
							$resultat = mysqli_query($db, $requete) or die("Error: ". mysqli_error($db));
							$row = mysqli_fetch_array($resultat, MYSQLI_NUM);
							$_SESSION['type_diplome'] = $row[2];
							$_SESSION['option_diplome'] = $row[3];
							$_SESSION['annee_diplome'] = $row[4];
							$_SESSION['mention_diplome'] = $row[5];
							$_SESSION['universite_diplome'] = $row[6];
							
							// Récupération de la formation choisie
							$requete = "SELECT ID_SPECIALITE FROM `preinscription` WHERE `id_candidat`=".$_SESSION["ID_CANDIDAT"].";";
							$resultat = mysqli_query($db, $requete) or die("Error: ". mysqli_error($db));
							$row = mysqli_fetch_array($resultat, MYSQLI_NUM);
							$id_specialite= $row[0];
							$requete = "SELECT LIBELLE FROM specialite WHERE ID_SPECIALITE='".$id_specialite."';";
							$resultat = mysqli_query($db, $requete) or die("Error: ". mysqli_error($db));
							$row = mysqli_fetch_array($resultat, MYSQLI_NUM);
							$_SESSION['option_formation']=$row[0];
							
                            
                            if (!$row)
                                echo ("
			                        <p class='centered' style='color: red; font-size : 1.5em'> ERREUR DE CONNEXION !! Aucun dossier n'est associé à cette adresse email. <br/>
                                    <br/>
                                    <a href=\"index.php\" alt=\"Lien vers préinscription\" class='btn btn-primary' style='font-size : 1.5em'>Inscrivez-vous</a>
                                    </p>
                                    
			                        <br/>
			                        <br/>
			                    ");
                            else {	//email existe dans BDD
		                
                                if ($passwd == $_SESSION['password'])
								    header('Location: etape1.php');
						        else {
								    echo "
				                        <p class='centered' style='color: red'> Identifiant ou Mode de passe incorrect ! Réessayez svp ... </p>
				                   
				                        <form class='col-lg-12' action='connexion.php' method='POST'>
					                       <div class='form-group'>
									            <input type='text' class='form-control' name='email' placeholder='Entrer votre adresse email' />
									       </div>
									         <div class='form-group'>
									            <input type='password' class='form-control' name='password' placeholder='Entrer votre adresse mot de passe' />
									       </div>
										        <span class='input-group-btn'>
								                   <button class='btn btn-primary btn-lg btn-block' type='submit'>ENVOYER</button>
								                </span>
					                    </form>
				                        <br/>
				                        <br/>
				                        <br/>
				                        <br/>
				                        <br/>
				                        <br/>
				                        <br/>
				                        "; 
							    }
                            };
                            
						
                        } else {
							echo "
			                    <p class='centered' style='color: red'> ERREUR DE CONNEXION !! Veuillez contacter l'administrateur du système. Merci. </p>
			                    <br/>
			                    <br/>
			                    ";
						}
					}
                    ?>
                	     
			</div>
		</div>

		<div id="footerwrap">
			<div class="container">
				<h4>Created by <a href="http://code.google.com/p/master2syscom" target="_blank">DIC1 Info ESP</a> - Copyright 2014</h4>
			</div>
		</div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
		
	<script src="assets/js/jquery.min.js"></script>
	<script type="text/javascript" src="../assets/js/modernizr.custom.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrapValidator.min.js"></script>
	
	<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../assets/js/retina.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="../assets/js/smoothscroll.js"></script>
	<script type="text/javascript" src="../assets/js/jquery-func.js"></script>
	<script>	
		$(document).ready(function() {
	    $('.col-lg-12').bootstrapValidator({
	        message: 'This value is not valid',
	        feedbackIcons: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {
	            email: {
	                validators: {
	                    notEmpty: {
	                        message: 'Merci de bien remplir cette partie.'
	                    },
	                    emailAddress: {
	                        message: 'Merci d\'entrer une adresse mail valide.'
	                    }
	                }
	            }
	        }
	    });
	});
</script>
  </body>
</html>